package ntd.util.str.tool;

import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.StrUtil;

import java.time.LocalDateTime;

public class UtilHex {

    public static String hexSplit2ToInt(String hexString) {
        String[] split = StrUtil.split(hexString, 2);

        StringBuffer stringBuffer = new StringBuffer();
        for (String str : split) {
            stringBuffer.append(StrUtil.padPre(String.valueOf(Integer.parseInt(str, 16)), 2, "0"));
        }
        return stringBuffer.toString();
    }

    public static String hex2ToLocalDateTime(String hexString) {
        LocalDateTime localDateTime = LocalDateTimeUtil.parse(hexSplit2ToInt(hexString), "yyyyMMdd");
        return LocalDateTimeUtil.format(localDateTime, "yyyy-MM-dd");
    }

    public static String hexToDouble(String hexString) {
        return String.valueOf(Float.intBitsToFloat(Integer.valueOf(hexString, 16)));
    }

}
